// pages/tabList/tabList.js
const app = getApp()
var postLogin = require("../../utils/wh.js");
var WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
    enterprise: [],
    latitude: '',
    longitude: '',
    setting:{},
    title: "测试",
    markers: [{
      id: 1,
      latitude: '',
      longitude: '',
      commpany_name: "",//公司名称
    }],
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    
    wx.showLoading({
      title: '加载中•••',
      // mask: true
    })
    postLogin.Post('/api/company.index/introduce', {}, that.enterprise);//公司简介
    that.get_app_setting();
  },
  onShow: function (options) {
    
  },
  
  enterprise: function (res) {
    let that = this;
    wx.hideLoading();


    that.setData({
      enterprise: res,
      partner: res.album,

     
    })
  },
  //获取小程序设置
  get_app_setting:function(){
    let that=this;

    postLogin.Post('/api/setting/get',{},function(res){
      let markers = that.data.markers;
      markers.latitude = res.lat;
      markers.longitude = res.lng;
      markers.commpany_name = res.map_name;
      that.setData({
        setting: res, 
        latitude: res.lat,
        longitude: res.lng,
        markers: markers
        });
      console.log(markers)
    })

    
  },
  // 打电话
  call:function(){
    let that=this;
    let setting= that.data.setting;
    let tell = setting.service_tel;

    if(tell == '' || tell == undefined){

      wx.showModal({
        title: '提示', content: '联系电话未设置，不能联系', showCancel: false
      })
      return;
    }
    wx.makePhoneCall({
      phoneNumber: tell,
    })
  },

  
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  go: function () {
    var that = this;
    let setting = that.data.setting;
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度  
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        var latitudeIdx = Number(setting.lat);
        var longitudeIdx = Number(setting.lng);
        var map_name = setting.map_name;
        wx.openLocation({
          latitude: latitudeIdx,
          longitude: longitudeIdx,
          name: map_name,
          scale: 15
        })
      }
    })
  },
  
})